extends Spatial

var mat: SpatialMaterial = null
var anim: Dictionary = {}
onready var tween: Tween = $Tween

signal animation_completed()

func _ready():
	mat = preload("res://materials/highlight2.tres").duplicate()
	$MeshInstance.material_override = mat
# warning-ignore:return_value_discarded
	tween.interpolate_method(self, "update_animation_timer", 0.0, 1.0, \
		anim.get("time", 1.0))
# warning-ignore:return_value_discarded
	tween.start()

func update_animation_timer(t: float):
	if Engine.editor_hint or anim.empty() or is_queued_for_deletion():
		return

	match anim:
		{"flash": var _c, ..}:
			if t < 0.9999:
				match _c:
					"red":
						var f: float = fmod(t * 4.0, 2.0)
						f = min(f, 2.0 - f) * 0.4
						mat.albedo_color = Color(1.0, 0.0, 0.0, f)
				return

	queue_free()
	anim.clear()
	emit_signal("animation_completed")
